package com.sr.exception;

import com.sr.enums.BaseCodeEnum;

/**
 * @author xiaochi
 * @date 2022/4/27 16:05
 * @desc BusinessException
 */
public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = -6492084603174404597L;

    private int code;
    private String messgae;

    public BusinessException(String messgae){
        super(messgae);
        this.messgae = messgae;
    }

    public BusinessException(int code,String messgae){
        super(messgae);
        this.code = code;
        this.messgae = messgae;
    }

    public BusinessException(int code,String messgae,Throwable cause){
        super(messgae,cause);
        this.code = code;
        this.messgae = messgae;
    }

    public BusinessException(BaseCodeEnum baseCodeEnum){
        this(baseCodeEnum.getCode(), baseCodeEnum.getMessage());
    }

    public int getCode() {
        return this.code;
    }

    /**
     * 使用方法抛出异常
     * @param baseCodeEnum
     */
    public static void display(BaseCodeEnum baseCodeEnum){
        throw new BusinessException(baseCodeEnum);
    }
}
